home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Bill's Win32Asm Page / fpu1.txt < prev    next >
Text File  |  2000-05-25  |  8KB  |  224 lines

  1. Introduction to Floating Point Programming
  2. By Bill T.
  3.  
  4. This article will give a general overview of the Intel Architcture Floating
  5. Point Unit (FPU).  It will cover the FPU's architecture and instruction set.
  6.  
  7.  
  8. FPU Data Formats
  9. -----------------------------------------------------------------------------
  10.                   Length   Precision  Range (Approx)
  11.   Single Real     32 bit   24 bit     1.18e-38 to 3.40e38
  12.   Double Real     64 bit   53 bit     2.23e-308 to 1.79e308
  13.   Extended Real   80 bit   64 bit     3.37e-4932 to 1.18e4932
  14.   Word Integer    16 bit   15 bit     -32768 to 32768
  15.   Short Integer   32 bit   31 bit     -2.14e9 to 2.14e9
  16.   Long Integer    64 bit   63 bit     -9.22e18 to 9.22e18
  17.   Packed BCD      80 bit   18         (-1e18 + 1) to (1e18 - 1)
  18.  
  19.  
  20.  
  21. FPU Data Registers
  22. -----------------------------------------------------------------------------
  23.  
  24.   Data Registers
  25.       _ _________ _______________________________________
  26.   R7 |_|_________|_______________________________________|
  27.   R6 |_|_________|_______________________________________|
  28.   R5 |_|_________|_______________________________________|
  29.   R4 |_|_________|_______________________________________|
  30.   R3 |_|_________|_______________________________________|
  31.   R2 |_|_________|_______________________________________|
  32.   R1 |_|_________|_______________________________________|
  33.   R0 |_|_________|_______________________________________|
  34.     80 79        63                                      0
  35.     Sign  Exponent                             Significand
  36.  
  37.                            ______________________________
  38.   FPU Instruction Pointer |______________________________|
  39.   FPU Operand Pointer     |______________________________|
  40.                          47                              0
  41.                                           _______________
  42.   Control Register                       |_______________|
  43.   Status Register                        |_______________|
  44.   Tag Register                           |_______________|
  45.   Opcode                                     |___________|
  46.                                         15   10          0
  47.  
  48.  
  49.  
  50.  
  51. FPU Data Register Stack:
  52.      ___________________________
  53.   7 |___________________________|                    Stack 
  54.   6 |___________________________| ST(2)              Growth
  55.   5 |___________________________| ST(1)                |
  56.   4 |___________________________| ST(0)  TOP=100b      |
  57.   3 |___________________________|                     \|/
  58.   2 |___________________________|                      `
  59.   1 |___________________________|
  60.   0 |___________________________|
  61.  
  62.  
  63. Status Register:
  64.    ___________________________________________________________
  65.   |___|___|___________|___|___|___|___|___|___|___|___|___|___|
  66.     B   C3     TOP      C2  C1  C0  ES  SF  PE  UE  OE  ZE  IE 
  67.     
  68.   B     - FPU Busy
  69.   C0-C3 - Condition Codes
  70.   TOP   - Top of Stack Pointer
  71.   ES    - Error Summary Status
  72.   SF    - Stack Fault
  73.   PE    - Precision Exception
  74.   UE    - Underflow Exception
  75.   OE    - Overflow Exception
  76.   ZE    - Zero Divide Exception
  77.   DE    - Denormailzed Operand Exception
  78.   IE    - Invalid Operation Exception
  79.  
  80.  
  81.  
  82. FPU Instruction Set
  83. -----------------------------------------------------------------------------
  84.  
  85. Data Transfer Instructions:
  86.  
  87.   FLD    src = [st(), mem32, mem64]
  88.          Load Real
  89.          Pushes real operand (from memory or FPU data register) onto
  90.          the top of the FPU stack.  If the operand is a single or double real
  91.          number, it is automatically converted to extended real formt.
  92.  
  93.   FST    dest = [mem32, mem64, mem80, st()]
  94.          Store Real
  95.          Copies the value on top of the FPU stack to the destination operand.
  96.  
  97.   FSTP   dest = [mem32, mem64, mem80, st()]
  98.          Store Real and Pop
  99.          Copies the top of the FPU stack to the destination operand and pops
  100.          the value off of the stack.
  101.  
  102.   FXCH   [st()]
  103.          Exchange Register Contents
  104.          Exchanges the top of the FPU stack with another FPU register.
  105.  
  106.   FILD   src = [mem32, mem64, mem80]
  107.          Load Integer
  108.          Converts integer operand to extended real format, the pushes it onto
  109.          the top of the FPU stack.
  110.  
  111.   FIST   dest = [mem32, mem64, mem80]
  112.          Store Integer
  113.          Converts value at the top of the FPU stack to an integer value, and
  114.          stores it in the destination.
  115.  
  116.   FISTP  dest = [mem32, mem64, mem80]
  117.          Store Integer and Pop
  118.          Converts the top of the FPU stack to an integer value, stores it in
  119.          the destination, and pops the value off the stack.
  120.  
  121.   FBLD   src = [bcd80]
  122.          Load Packed Decimal
  123.          Converts BCD source to extended real format and pushes it to the top
  124.          of the FPU stack.
  125.  
  126.   FBSTP  dest = [mem80]
  127.          Store Packed Decimal and Pop
  128.          Converts top of FPU stack to BCD format, stores it in destination,
  129.          and pops value off of the stack.
  130.  
  131.  
  132. Constant Load Instructions:
  133.   
  134.   These instructions push commonly used constants on to the top of the FPU 
  135.   stack (ST(0)).  These constants have extended real precision and are accurate
  136.   to approximately 19 digits.
  137.  
  138.   FLDZ      Load +0.0
  139.   FLD1      Load +1.0
  140.   FLDPI     Load PI
  141.   FLDL2T    Load log(2) 10  [log(base 2) of 10]
  142.   FLDL2E    Load log(2) e
  143.   FLDLG2    Load log(10) 2
  144.   FLDLN2    Load log(e) 2
  145.  
  146.  
  147. Arithmetic Instructions:
  148.  
  149.   The following instructions operate on the following types of operands:
  150.   - 2 FPU register values
  151.   - A Register value and a real or integer value in memory
  152.  
  153.   FADD(P)   Add Real [FADDP = Add real and pop]
  154.   FIADD     Add Integer
  155.   FSUB(P)   Subtract Real
  156.   FISUB     Subtract Integer from Real
  157.   FSUBR(P)  Reverse Subtract Real
  158.   FISUBR    Reverse Subtract Real from Integer
  159.   FMUL(P)   Multiply Real
  160.   FIMUL     Multiply Integer by Real
  161.   FDIV(P)   Divide Real
  162.   FIDIV     Divide Integer by Real
  163.   FDIVR(P)  Reverse Divide Real
  164.   FIDIVR    Reverse Divide Integer by Real
  165.  
  166.  
  167. Comparison Instructions:
  168.  
  169.   FCOM      Compare real and set FPU condition code flags
  170.   FUCOM     Unordered compare real and set FPU condition code flags
  171.   FICOM     Compare Integer
  172.   FCOMI     Compare real and set EFLAGS status flags
  173.   FUCOMI    Unordered compare real and set EFLAGS status flags
  174.   FTST      Test (Compare real with 0.0)
  175.   FXAM      Examine
  176.  
  177. Trigonometric Instructions:
  178.  
  179.   FSIN      Sine
  180.   FCOS      Cosine
  181.   FSINCOS   Sine and Cosine
  182.   FPTAN     Tangent
  183.   FPATAN    ArcTangent
  184.  
  185.   These instructions operate on the top one or two FPU Stack registers.
  186.   They return their results to the stack.
  187.   The operands must be given in radians.
  188.  
  189. Logarithm, Exponential, and Scale:
  190.  
  191.   FYL2X     Compute log (y * log[2] x)
  192.   FYL2XPI   Compute log epsilon (y * log[2] x)
  193.   F2XMI     Compute exponential (2^x - 1) 
  194.   FSCALE    Scale - multiplies source operand by power of 2
  195.  
  196. FPU Control Instructions:
  197.  
  198.   FINIT/FNINIT   Initialize FPU
  199.   FLDCW          Load FPU control word
  200.   FSTCW/FNSTCW   Store FPU control word
  201.   FSTSW/FNSTSW   Store FPU status word
  202.   FCLEX/FNCLEX   Clear FPU exception flags
  203.   FLDENV         Load FPU environment
  204.   FSTENV/FNSTENV Store FPU environment
  205.   FRSTOR         Restore FPU state
  206.   FSAVE/FNSAVE   Save FPU state
  207.   FINCSTP        Increment FPU register stack pointer
  208.   FDECSTP        Decrement FPU register stack pointer
  209.   FFREE          Free FPU register
  210.   FNOP           No operation
  211.   WAIT/FWAIT     Check for and handle pending unmasked FPU exceptions
  212.  
  213.  
  214. Conclusion
  215. -----------------------------------------------------------------------------
  216.  
  217. This is a very basic overview of the Floating Point Processor.
  218. Future articles will describe the actual use of the FPU and its
  219. instruction set.
  220.  
  221. -----------------------------------------------------------------------------
  222.  
  223. Copyright (C) 1999
  224. Bill T.  (billasm@usa.net)